/*
 * @Author: intellectual-seeker 3336339701@qq.com
 * @Date: 2025-03-24 14:52:31
 * @LastEditors: intellectual-seeker 3336339701@qq.com
 * @LastEditTime: 2025-03-24 16:42:30
 * @FilePath: /code/lesson25/named_pipe/PipeClient.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "Comm.hpp"

//client: 写，server: 读
int main()
{
    int wfd = open(Path, O_WRONLY);
    if(wfd < 0)
    {
        cerr << "open failed " << errno << " errstring: " << strerror(errno) << endl;
        return 1;
    }

    string inbuff;
    while(true)
    {
        cout << "Please Enter: ";
        getline(cin, inbuff);
        int n = write(wfd, inbuff.c_str(), inbuff.size());
        if(inbuff == "quit")
        {
            break;   
        }
        if(n < 0)
        {
            cerr << "write failed " << errno << " errstring: " << strerror(errno) << endl;
            break;
        }
    }

    close(wfd);

    return 0;
}